// packageE/addInvoice/addInvoice.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    form:{
      order_ids:'',
      invoice_type:'1',
      collect_name:"",
      invoice_identification_code:"",
      email:"",
      company_address:"",
      mobile:"",
      open_bank:"",
      bank_number:"",
      invoice_content_type:"1"
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      'form.order_ids':options.ids
    })
  },
  onChangeInput(e){
    this.data.form[e.currentTarget.dataset.name] = e.detail;
    this.setData({
      form:this.data.form
    })
  },
  onChange(e){
    this.data.form.invoice_type = e.detail;
    this.setData({
      form:this.data.form
    })
  },
  onChange1(e){
    this.data.form.invoice_content_type = e.detail;
    this.setData({
      form:this.data.form
    })
  },
  confirm() {
    if(this.data.form.collect_name == ""){
      wx.showToast({
        title: '请输入发票抬头',
        icon: "none",
        duration: 1000,
      });
      return false
    }
    if(this.data.form.invoice_type==2 && this.data.form.invoice_identification_code == ""){
      wx.showToast({
        title: '请输入发票税号',
        icon: "none",
        duration: 1000,
      });
      return false
    }

    if(this.data.form.email == ""){
      wx.showToast({
        title: '请输入发送邮箱',
        icon: "none",
        duration: 1000,
      });
      return false
    }


    var that = this;
    let urlStr = app.getNetAddresss("invoice.invoice.apply");
    let json = that.data.form;
    app._postNetWork({
      url: urlStr,
      data: json,
      success: function (resdata) {
        if (resdata.data.result == 1) {
          wx.navigateBack({
            delta:1
         })
        }else{
          wx.showToast({
            title: resdata.msg,
            icon: "none",
            duration: 1000,
          });
        }
        
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
});
